package com.itheima.controller;

import com.itheima.pojo.Flux;
import com.itheima.pojo.Result;
import com.itheima.pojo.Sif;
import com.itheima.service.FluxService;
import com.itheima.service.MeteorologyService;
import com.itheima.service.SifService;
import com.itheima.utils.AliOssUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/data")
public class DataController {

    @Autowired
    private FluxService fluxService;

    @Autowired
    private MeteorologyService meteorologyService;

    @Autowired
    private SifService sifService;

    // 查询数据库中数据分布情况，
    @GetMapping("/findDataDistribution")
    public Result<Map<String, Integer>> findFluxByTimeRange() {
        //  得到每种类型的数量
        Integer fluxNumber = fluxService.findFluxAllNumber();
        Integer meteorologyNumber = meteorologyService.findMeteorologyAllNumber();
        Integer sifNumber = sifService.findSifAllNumber();
        Integer phenologyNumber = 365;
        Integer other = 79;

        //  封装返回json类型的例如{sif: 2045,flux:200,meteorology:1000,phenlolgy:300,other:50}
        // 封装返回的 JSON 数据
        Map<String, Integer> dataDistribution = new HashMap<>();
        dataDistribution.put("flux", fluxNumber);
        dataDistribution.put("meteorology", meteorologyNumber);
        dataDistribution.put("sif", sifNumber);
        dataDistribution.put("phenology", phenologyNumber);
        dataDistribution.put("other", other);
        return Result.success(dataDistribution);
    }
}
